<html><head><META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>3.&nbsp;Getting Started (ANT)</title><link href="../skin/css/doc.css" rel="stylesheet" type="text/css"><meta content="DocBook XSL Stylesheets V1.66.1" name="generator"><link rel="start" href="userguide.html" title="EMMA User Guide"><link rel="up" href="userguide.html" title="EMMA User Guide"><link rel="prev" href="ar01s02s03.html" title="2.3.&nbsp;Offline mode: separating instrumentation and execution"><link rel="next" href="ar01s03s02.html" title="3.2.&nbsp;<emmajava>: instrumenting Java classes
on-the-fly"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table summary="Navigation header" width="100%"><tr><th align="center" colspan="3">3.&nbsp;Getting Started (<span class="emphasis"><em>ANT</em></span>)</th></tr><tr><td align="left" width="20%"><a accesskey="p" href="ar01s02s03.html"><img src="../images/prev.gif" alt="Prev"></a>&nbsp;</td><th align="center" width="60%">&nbsp;</th><td align="right" width="20%">&nbsp;<a accesskey="n" href="ar01s03s02.html"><img src="../images/next.gif" alt="Next"></a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="introANT"></a>3.&nbsp;Getting Started (<span class="emphasis"><em>ANT</em></span>)</h2></div></div></div><p>This section introduces EMMA ANT tasks. It starts with an example
of how to run an application from ANT so that coverage instrumentation is
performed on-the-fly, as the classes are loaded by the JVM, and then repeats
the same process by breaking it into distinct
instrumentation/execution/reporting steps. The ANT logic sequence will be
equivalent to what was described previously, in <a href="ar01s02.html" title="2.&nbsp;Getting Started (command line)">Section&nbsp;2, &ldquo;Getting Started (<span class="emphasis"><em>command line</em></span>)&rdquo;</a>. Additionally, the ANT <tt class="filename">build.xml</tt> files
created below will have logic for enabling and disabling coverage through
ANT command line.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Sample source code and ANT build files</h3><p>The source code located in <tt class="filename">examples/src</tt>
directory of EMMA distribution is used for all examples in this tutorial.
EMMA distribution also includes two sample ANT buildfiles,
<tt class="filename">build-onthefly.xml</tt> and
<tt class="filename">build-offline.xml</tt>, that correspond to the two
approaches to collecting coverage. Although it would have been possible to
keep everything in a single file, using distinct files allows for more
clarity.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="setupANT"></a>3.1.&nbsp;Adding EMMA tasks to your ANT build</h3></div></div></div><p>EMMA ANT tasks can be deployed in any of the many ways available
for custom ANT taskdefs. This tutorial assumes that you have an EMMA
distribution directory that contains both <tt class="filename">emma.jar</tt> and
<tt class="filename">emma_ant.jar</tt>. The latter archive is what contains EMMA
taskdefs, however, both archives need to be visible to ANT. The easiest way
to accomplish this is with the following definitions in your
<tt class="filename">build.xml</tt>:</p><pre class="programlisting">
  &lt;!-- directory that contains emma.jar and emma_ant.jar: --&gt;
  &lt;property name="emma.dir" value="${basedir}/../lib" /&gt;

  &lt;path id="emma.lib" &gt;<a name="A0-co" href="ar01s03.html#A0"><img border="0" alt="1" src="../images/callouts/1.png"></a>
    &lt;pathelement location="${emma.dir}/emma.jar" /&gt;
    &lt;pathelement location="${emma.dir}/emma_ant.jar" /&gt;
  &lt;/path&gt;

  &lt;taskdef resource="emma_ant.properties" classpathref="emma.lib" /&gt;</pre><p>
      <div class="calloutlist"><table summary="Callout list" border="0"><tr><td align="left" valign="top" width="5%"><a name="A0"></a><a href="#A0-co"><img border="0" alt="1" src="../images/callouts/1.png"></a> </td><td align="left" valign="top"><p>Even though this path definition can be merged into the
<span><b class="command">&lt;taskdef&gt;</b></span>, a path element with this id will come in
handy later in the build.</p></td></tr></table></div></p></div></div><div class="navfooter"><hr><table summary="Navigation footer" width="100%"><tr><td align="left" width="40%"><a accesskey="p" href="ar01s02s03.html"><img src="../images/prev.gif" alt="Prev"></a>&nbsp;</td><td align="center" width="20%"><a accesskey="u" href="userguide.html"><img src="../images/up.gif" alt="Up"></a></td><td align="right" width="40%">&nbsp;<a accesskey="n" href="ar01s03s02.html"><img src="../images/next.gif" alt="Next"></a></td></tr><tr><td valign="top" align="left" width="40%">2.3.&nbsp;Offline mode: separating instrumentation and execution&nbsp;</td><td align="center" width="20%"><a accesskey="h" href="userguide.html"><img src="../images/home.gif" alt="Home"></a></td><td valign="top" align="right" width="40%">&nbsp;3.2.&nbsp;<span><b class="command">&lt;emmajava&gt;</b></span>: instrumenting Java classes
on-the-fly</td></tr></table></div></body></html>